package com.tensquare.gathering.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tensquare.gathering.mapper.GatheringMapper;
import com.tensquare.gathering.domain.Gathering;
import com.tensquare.gathering.service.IGatheringService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 活动Service业务层处理
 * 
 * @author hbxfwf
 * @date 2021-08-25
 */
@Service
@Slf4j
public class GatheringServiceImpl implements IGatheringService 
{
    @Autowired
    private GatheringMapper gatheringMapper;

    /**
     * 查询活动
     * 
     * @param id 活动主键
     * @return 活动
     */
    @Override
    public Gathering selectGatheringById(String id)
    {
        return gatheringMapper.selectGatheringById(id);
    }

    /**
     * 查询活动列表
     * 
     * @param gathering 活动
     * @return 活动
     */
    @Override
    public List<Gathering> selectGatheringList(Gathering gathering)
    {
        return gatheringMapper.selectGatheringList(gathering);
    }

    /**
     * 新增活动
     * 
     * @param gathering 活动
     * @return 结果
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int insertGathering(Gathering gathering)
    {
        log.info("当前 XID: {}", RootContext.getXID());
         int i = 10 / 0;
        return gatheringMapper.insertGathering(gathering);
    }

    /**
     * 修改活动
     * 
     * @param gathering 活动
     * @return 结果
     */
    @Override
    public int updateGathering(Gathering gathering)
    {
        return gatheringMapper.updateGathering(gathering);
    }

    /**
     * 批量删除活动
     * 
     * @param ids 需要删除的活动主键
     * @return 结果
     */
    @Override
    public int deleteGatheringByIds(String[] ids)
    {
        return gatheringMapper.deleteGatheringByIds(ids);
    }

    /**
     * 删除活动信息
     * 
     * @param id 活动主键
     * @return 结果
     */
    @Override
    public int deleteGatheringById(String id)
    {
        return gatheringMapper.deleteGatheringById(id);
    }

    /**
     * 功能: 查询活动
     * 参数:
     * 返回值: java.util.List<com.tensquare.gathering.domain.Gathering>
     * 时间: 2021/8/28 14:42
     */
    @Override
    public List<Gathering> findAll() {
        return gatheringMapper.selectGatheringList(null).stream().limit(9).collect(Collectors.toList());
    }
}
